package com.example.teamtribe.main.club.clubdetail;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.teamtribe.R;
import com.example.teamtribe.base.BaseActivity;
import com.example.teamtribe.common.IconTextView;
import com.example.teamtribe.database.Team;
import com.example.teamtribe.main.club.clubintroduce.ClubIntroduceActivity;
import com.example.teamtribe.main.club.clubmembers.MembersActivity;
import com.example.teamtribe.main.club.estimate.EstimateActivity;
import com.example.teamtribe.main.club.join.ApplyActivity;
import com.example.teamtribe.main.club.manage.ManageActivity;
import com.example.teamtribe.main.club.manage.finace.FinanceActivity;
import com.example.teamtribe.main.club.moment.MomentActivity;
import com.example.teamtribe.utils.Utility;

import org.litepal.crud.DataSupport;

import java.util.List;

public class ClubDetailActivity extends BaseActivity implements View.OnClickListener {

    private Team team;
    private int userId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_club_detail);
        team = getIntent().getParcelableExtra("team");
        ((TextView) findViewById(R.id.tv_title)).setText(team.getName());

        findViewById(R.id.ll_item_introduce).setOnClickListener(this);
        findViewById(R.id.ll_item_moment).setOnClickListener(this);
        findViewById(R.id.ll_item_members).setOnClickListener(this);
        findViewById(R.id.ll_item_join).setOnClickListener(this);
        findViewById(R.id.ll_item_finance).setOnClickListener(this);
        findViewById(R.id.ll_item_estimate).setOnClickListener(this);
        findViewById(R.id.ll_item_manage).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_item_introduce:
                Intent introduce = new Intent(ClubDetailActivity.this, ClubIntroduceActivity.class);
                introduce.putExtra("team", team);
                startActivity(introduce);
                break;
            case R.id.ll_item_finance:
                Intent finance = new Intent(ClubDetailActivity.this, FinanceActivity.class);
                startActivity(finance);
                break;
            case R.id.ll_item_estimate:
                Intent estimate = new Intent(ClubDetailActivity.this, EstimateActivity.class);
                startActivity(estimate);
                break;
            case R.id.ll_item_manage:
                Intent manage = new Intent(ClubDetailActivity.this, ManageActivity.class);
                manage.putExtra("team", team);
                startActivity(manage);
                break;
            case R.id.ll_item_join:
                Intent join = new Intent(ClubDetailActivity.this, ApplyActivity.class);
                join.putExtra("teamId", team.getRealId());
                startActivity(join);
                break;
            case R.id.ll_item_moment:
                Intent moment = new Intent(ClubDetailActivity.this, MomentActivity.class);
                moment.putExtra("mode", MomentActivity.MODE_TEAM);
                moment.putExtra("id", team.getRealId());
                startActivity(moment);
                break;
            case R.id.ll_item_members:
                Intent personnel = new Intent(ClubDetailActivity.this, MembersActivity.class);
                personnel.putExtra("team", team);
                startActivity(personnel);
                break;
            default:
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        List<Team> teams = DataSupport.where("realId = ?", team.getRealId() + "").find(Team.class);
        team = teams.get(0);
        ((TextView) findViewById(R.id.tv_title)).setText(team.getName());
    }
}
